package com.yhao.stock.common.stock;

import com.yhao.stock.common.utils.CSVUtil;
import com.yhao.stock.entity.DayInfo;
import lombok.extern.slf4j.Slf4j;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * @author : yhao
 * @Date : 2023/12/6 - 7:34
 * @Desc : 连续下跌分析
 */
@Slf4j
public class ContinueFallAna {

    /**
     * @desc 求下跌趋势天数
     */
    public static void findDowntrend() {
        List<String> resultList = new ArrayList<>();
        List<DayInfo> stockList = StockBaseUtil.getStockByCode("603721");
        String content = "";
        for (DayInfo dayInfo : stockList) {
            String code = dayInfo.getdCode();
            String name = dayInfo.getdName();
            System.out.println("执行到    =======    code=[" + code + "]   name=[" + name + "]");
            List<DayInfo> dayInfoByCode = StockBaseUtil.getDayInfoByCode(dayInfo.getdCode());
            Integer count = StockBaseUtil.dayInfoSdCountNew1214(dayInfoByCode);
            content = code + "," + name + "," + count + "," + dayInfoByCode.size() + "," + Double.parseDouble((count / dayInfoByCode.size()) + "");
            resultList.add(content);
        }
        CSVUtil.exportCsv("D:\\CFNew1215.csv", resultList);
        System.out.println("ContinueFallAna  findNew 执行完成" + LocalDateTime.now());
    }


    /**
     * @desc 最大下跌天数
     */
    public static void findDeclineCount() {
        List<String> resultList = new ArrayList<>();
        List<DayInfo> stockList = StockBaseUtil.getStock();
        String content = "";
        for (DayInfo dayInfo : stockList) {
            String code = dayInfo.getdCode();
            String name = dayInfo.getdName();
            System.out.println("执行到    =======    code=[" + code + "]   name=[" + name + "]");
            List<DayInfo> dayInfoByCode = StockBaseUtil.getDayInfoByCode(dayInfo.getdCode());
            Integer count = StockBaseUtil.declineCount(dayInfoByCode);
            content = code + "," + name + "," + count;
            resultList.add(content);
        }
        CSVUtil.exportCsv("D:\\DeclineCount.csv", resultList);
        System.out.println("ContinueFallAna  findDeclineCount 执行完成" + LocalDateTime.now());
    }

    public static void main(String[] args) {
        // find();
        // findDowntrend();
        findDeclineCount();
    }


}
